<template>
  <div class="main-box">
    <div :class="['container', 'container-register', { 'is-txl': isLogin }]">
      <el-form
      :model="resetForm"
      ref="resetForm">
        <h2 class="title">创建账户</h2>
        <span class="text">你需要输入你的个人信息进行注册账户</span>
        <el-row>
        <el-col :span="12"> <el-form-item  prop="idcard">
        <el-input v-model="resetForm.idcard" type="text" placeholder="身份证号" /></el-form-item>
        <el-form-item  prop="name">
        <el-input v-model="resetForm.name" type="text" placeholder="姓名" /></el-form-item>
        <el-form-item  prop="telephone">
        <el-input v-model="resetForm.telephone" type="text" placeholder="手机号码" /></el-form-item>
        <el-form-item  prop="address">
        <el-input v-model="resetForm.address" type="text" placeholder="住址" /></el-form-item></el-col>
        <el-col :span="12"><el-form-item  prop="sex">
        <el-radio-group v-model="resetForm.sex" style="margin-left: 20px;">
            <el-radio label="1">男</el-radio>
            <el-radio label="0">女</el-radio>
        </el-radio-group>
        </el-form-item>
        <el-form-item  prop="password">
        <el-input v-model="resetForm.password" autocomplete="off" type="password"  show-password  placeholder="密码" /> </el-form-item>
        <el-form-item  prop="checkPass">
        <el-input v-model="checkPass" type="password" autocomplete="off"  show-password placeholder="再次确认密码" /></el-form-item></el-col></el-row>
       
        
        <div class="primary-btn" @click=" register">立即注册</div>
      </el-form>
    </div>
    <div
      :class="['container', 'container-login', { 'is-txl is-z200': isLogin }]"
    >
    <el-form :model="loginForm" status-icon :rules="rules" ref="loginForm" class="demo-ruleForm" >
        <h2 class="title">登录网站</h2>
        <span class="text">你可以用身份证号登录系统，你也可以用你的手机号进行登录</span>
        
      <el-form-item prop="username">
        <el-input placeholder="用户名" v-model="loginForm.username"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password"  show-password placeholder="密码" v-model="loginForm.password" @keyup.enter="loginIn"></el-input>
      </el-form-item>
        <div class="primary-btn"  @click="loginIn">立即登录</div>
      </el-form>
    </div>
    <div :class="['switch', { login: isLogin }]">
      <div class="switch__circle"></div>
      <div class="switch__circle switch__circle_top"></div>
      <div class="switch__container">
        <h2>{{ isLogin ? "你好用户 " : "欢迎使用 " }}</h2>
        <p>
          {{
            isLogin
              ? "输入你的个人信息，注册一个系统用户账号"
              : "请使用你的个人信息进行登录"
          }}
        </p>
        <div class="primary-btn" @click="isLogin = !isLogin">
          {{ isLogin ? "立即注册" : "立即登录" }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ElMessage, ElMessageBox } from "element-plus";
export default {
  name: "Userlogin",
  data() {
     // 对用户名进行校验
     var validateName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请输入用户名'))
      } else {
        callback()
      }
    }
  // 对密码进行校验
    var validatePassword = (rule, value, callback) => {
      if (value === '') {
        return callback(new Error(('请输入密码')))
      } else {
        callback()
      }
    }
    return {
      isLogin: false,
      checkPass: null,

      resetForm:{},
      loginForm: {
        username: '',
        password: ''
      },
      rules: {
        username: [
        //
        //trigger: 'blur'：当失去焦点时（光标不显示的时候），触发此提示
          { validator: validateName, message: '请输入用户名', trigger: 'blur'}
        ],
        password: [
          { validator: validatePassword, message: '请输入密码', trigger: 'blur'}
        ]
      }
    }
        
      },
    methods: {
      //登录
      loginIn(loginForm) {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.$http
            .post("/inoculations/user/login", this.loginForm)
            .then((res) => {
              if (res.statusCode == "200") {
                localStorage.setItem("token", res.data.userToken);
                ElMessage({
                  message: "登录成功！",
                  type: "success",
                });
                this.$store.state.UserDate = true;
                this.$router.push("/mineself");
              } else if(res.statusCode == "500") {
                ElMessage.error("账号或密码错误！");
              }
            })
            .catch(() => {
              ElMessage.error("登录失败！");
            });
        } else {
          ElMessage.error("请填写！");
          return false;
        }
      });
    },
    register() {
            this.$http
              .post("/inoculations/user/save", this.resetForm)
              .then((res) => {
                if (res.statusCode == "200") {
                  ElMessage({
                    message: "成功！",
                    type: "success",
                  });
                  this.isLogin = true;
                  
                }
              })
              .catch(() => {
                ElMessage.error("失败！");
              });
    },
  }
  }
</script>

<style scoped>
.main-box {
  position: relative;
  margin: auto;
  margin-top: 80px;
  width: 80%;
  height: 600px;
  padding: 25px;
  background-color: #ecf0f3;
  box-shadow: 10px 10px 10px #d1d9e6, -10px -10px 10px #f9f9f9;
  border-radius: 12px;
  overflow: hidden;
}
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  top: 0;
  width:60%;
  height: 100%;
  padding: 25px;
  background-color: #ecf0f3;
  transition: all 1.25s;
}
.el-form {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 100%;
  height: 100%;
  color: #a0a5a8;
}
.title {
  font-size: 34px;
  font-weight: 700;
  line-height: 3;
  color: #181818;
}
.text {
  margin-top: 30px;
  margin-bottom: 12px;
}
.el-input {
    width:300px;
    margin-left: 10px;
}
.el-input >>> .el-input__inner {
  height: 40px;
  margin: 4px 0;
  padding-left: 25px;
  font-size: 13px;
  letter-spacing: 0.15px;
  border: none;
  outline: none;
  /* font-family: 'Montserrat', sans-serif; */
  background-color: #ecf0f3;
  transition: 0.25s ease;
  border-radius: 8px;
  box-shadow: inset 2px 2px 4px #d1d9e6, inset -2px -2px 4px #f9f9f9; 
}
.el-input >>> .el-input__wrapper{
    background-color: #ecf0f3;
    box-shadow: none;
}
/* .el-form-item {
    margin-bottom: 0;
} */
.el-input::placeholder {
  color: #a0a5a8;
}

.container-register {
  z-index: 10;
  left: calc(90% - 50%);
}
.container-login {
  left: calc(100% - 50%);
  z-index: 0;
}
.is-txl {
  left: 0;
  transition: 1.25s;
  transform-origin: right;
}
.is-z200 {
  z-index: 20;
  transition: 1.25s;
}
.switch {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 35%;
  padding: 50px;
  z-index: 20;
  transition: 1.25s;
  background-color: #ecf0f3;
  overflow: hidden;
  box-shadow: 4px 4px 10px #d1d9e6, -4px -4px 10px #f9f9f9;
  color: #a0a5a8;
}
.switch__circle {
  position: absolute;
  width: 50%;
  height: 500px;
  border-radius: 50%;
  background-color: #ecf0f3;
  box-shadow: inset 8px 8px 12px #d1d9e6, inset -8px -8px 12px #f9f9f9;
  bottom: -60%;
  left: -60%;
  transition: 1.25s;
}
.switch__circle_top {
  top: -30%;
  left: 60%;
  width: 30%;
  height: 300px;
}
.switch__container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  position: absolute;
  width: 60%;
  padding: 50px 55px;
  transition: 1.25s;
}
h2 {
  font-size: 34px;
  font-weight: 700;
  line-height: 3;
  color: #181818;
}
p {
  font-size: 14px;
  letter-spacing: 0.25px;
  text-align: center;
  line-height: 1.6;
}

.login {
  left: calc(100% - 40%);
}
.switch__circle {
  left: 0;
}

.primary-btn {
  width: 180px;
  height: 50px;
  border-radius: 25px;
  margin-top: 20px;
  text-align: center;
  line-height: 50px;
  font-size: 14px;
  letter-spacing: 2px;
  background-color: #00BFFF;
  color: #f9f9f9;
  cursor: pointer;
  box-shadow: 8px 8px 16px #d1d9e6, -8px -8px 16px #f9f9f9;
}
.primary-btn:hover {
  box-shadow: 4px 4px 6px 0 rgb(255 255 255 / 50%),
    -4px -4px 6px 0 rgb(116 125 136 / 50%),
    inset -4px -4px 6px 0 rgb(255 255 255 / 20%),
    inset 4px 4px 6px 0 rgb(0 0 0 / 40%);
}
</style>
